<?php
namespace app\home\controller;

use app\home\common\Common;
use app\home\common\Page;
use app\home\common\Pagetwo;
use app\infrastructure\uri\Request;
use app\infrastructure\uri\Uri;
use think\Db;

/**
 * Created by PhpStorm.
 * User: YD
 * Date: 2017/4/26
 * Time: 16:52
 */
class Toolcol extends Common
{
    private $client;
    public  function  __construct(){
        parent::__construct();
        $this->client=new Request();
    }
    public function google(){
        return view();
    }

    public function findUser(){
        $where=[];
        if(isset($_GET['email']) && !empty($_GET['email'])){
          $where['email']=['LIKE','%'.$_GET['email'].'%'];
        }
        if(isset($_GET['phone']) && !empty($_GET['phone'])){
            $where['phoneNumber']=['LIKE','%'.$_GET['phone'].'%'];
        }
        if(isset($_GET['firstname']) && !empty($_GET['firstname'])){
            $where['firstname']=['LIKE','%'.$_GET['firstname'].'%'];
        }
        if(isset($_GET['middlename']) && !empty($_GET['middlename'])){
            $where['middlename']=['LIKE','%'.$_GET['middlename'].'%'];
        }
        if(isset($_GET['lastname']) && !empty($_GET['lastname'])){
            $where['lastname']=['LIKE','%'.$_GET['lastname'].'%'];
        }
        if(!empty($where)){
            $user=Db::table('usercertifies')
                ->where($where)
                ->field('user_id,phoneNumber,email,firstname,middlename,lastname')
                ->find();
        }
        if(empty($user)){
          $user=[
              "user_id"=>'',
              "phoneNumber"=>'',
              "email"=>'',
              "firstname"=>'',
              "middlename"=>'',
              "lastname"=>''
          ];
        }
        $this->assign('product',$user);
        return view();
    }

    /**
     * 定时任务列表
     */
    public function cronTabList(){
        $data=Db::table("crontab_auto")
            ->select();
        $this->assign('data',$data);
        return view();
    }

    /**
     * 添加任务
     */
    public function addCrontab(){
        if(\think\Request::instance()->isAjax()){
            $data=[
                "type"=>$_POST['type'],
                "start_time"=>strtotime($_POST['start_time'])*1000,
                "exe_time"=>strtotime($_POST['exe_time'])*1000,
                "status"=>1,
                "content"=>$_POST['content']
            ];
            $url="http://120.77.183.99:3020/api/crontab";
            $res=$this->client->getArrayData($url,$data,3);
            return $res;
        }
        return view();
    }
}